package org.jimm.app;

import org.jimm.protocol.XStatusInfo;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;

/**
 * @author r.u.s.h.a.n.
 */
public class XStatusAdapter extends BaseAdapter {

    Context context;

    public XStatusAdapter(Context applicationContext) {
        this.context = applicationContext;
    }

    @Override
    public int getCount() {
        return XStatusInfo.icons.length;
    }

    @Override
    public Object getItem(int position) {
        return XStatusInfo.icons[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        if (XStatusInfo.icons == null) return null;

        if (convertView == null) {
            convertView = new ImageView(context);
            convertView.setLayoutParams(new GridView.LayoutParams(36, 36));
        }

        ImageView view = (ImageView) convertView;
        view.setScaleType(ImageView.ScaleType.CENTER);
        view.setImageResource((Integer) XStatusInfo.icons[position]);

        return view;
    }
}